package com.bdth.bdthcms.controller;

import com.bdth.bdthcms.entity.User;
import com.bdth.bdthcms.service.UserService;
import com.bdth.bdthcms.vo.MessageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by Administrator on 2020/8/10.
 */
@Controller
public class HomeController extends BaseController {

    @Autowired
    private UserService userService;

    @RequestMapping("/")
    public String index(HttpServletRequest request, HttpServletResponse response){
        User bean = (User) request.getSession().getAttribute("loginUser");
        if(bean==null){
            return "sys/login";
        }
        if(bean.getGroupid()==0)
            return "sys/admin";
        else
            return "sys/user";
    }

    @RequestMapping("/portal/index")
    public String index(){
        return "portal/index";
    }

    @RequestMapping(value = "/sys/modifypwd", method = RequestMethod.GET)
    public String modifyPassword(){
        return "sys/modifypwd";
    }

    @RequestMapping(value = "/sys/changePassword", method = RequestMethod.POST)
    @ResponseBody
    public MessageResult changePassword(String userNameId, String password){
        boolean flag = userService.changePwd(userNameId,password);
        if(flag)
            return MessageResult.getSuccess("操作成功");
        else
            return MessageResult.getError("500","操作失败");
    }
}
